<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
<title>部门管理</title>
<link rel="stylesheet" type="text/css" href="${ctx}/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${ctx}/easyui/easyui_my.css">
<link rel="stylesheet" type="text/css" href="${ctx}/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="${ctx}/css/css.css" />
<script type="text/javascript" src="${ctx}/js/jquery-1.7.min.js"></script>
<script type="text/javascript" src="${ctx}/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${ctx }/easyui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="${ctx}/js/common.js"></script>
</head>

<body class="easyui-layout"  options="border:false">
	<div data-options="region:'north',height:72,border:false" style="padding-left:10px;padding-right: 10px;padding-top: 5px;">
		<div class="xinxichaxunkuangz1">
			<div class="dashujtiaojianxuanxiangkuan">
				<div class="dashujtiaojianxuanxiangkuan_lie">
						<div class="tiaojian_key">部门查询：</div>
						<div class="tiaojian_values">
							<ul class="tiaojian_values_limian">
								<li><input id="ggSelect" name="ggSelect" type="text" class="shurukuangkais" value="--部门代码或名称--" onblur="InputBlur('ggSelect','--部门代码或名称--')" onfocus="InputFocus('ggSelect','--部门代码或名称--')" /></li>
							</ul>
						</div>
				</div>
				<div class="chaxunchongzhianniu">
					<a href="javascript:AddWindow()" class="sousuocx">添加</a>
					<a href="javascript:deleteUsers()" class="congzhim">删除</a>
					<a href="javascript:queryDataGrid()" class="congzhim">查询</a>
				</div>
			</div>
		</div>
	</div>
	<div data-options="region:'center',border:false" style="padding-left:10px;padding-right: 10px">
		<div class="easyui-layout xinxichaxunkuangz2" data-options="fit:true,border:false">
			<div class="tupianqiehuantop" data-options="region:'north',border:false" style="height: 40px">
              	<span class="chaxunjieguosd">搜索结果</span>
     		</div>
     		<div data-options="region:'center',border:false">
     			<table id="TableData" data-options="fit:true"></table>
     		</div>
     		<jsp:include page="/WEB-INF/content/department/addOrUpdateUser.jsp"/>
		</div>
	</div>
 				
<script type="text/javascript">
$(function(){
	initTable();
	
	//初始化Ajax表单提交
	$("#saveOrUpdateDevForm").form({
		url:'${ctx }/department/saveDepartment.htm',
		onSubmit:function(){//提交前校验
			return true;
		},
		success:function(data){//ajax提交后获取数据库返回信息
			if(data == 'true'){
				cancelUpdateDev();
				$("#TableData").datagrid("load");
			}
			else{
				$.messager.show({
					title:'操作失败',
					msg:'操作失败，请联系管理人员',
					timeout:5000,
					showType:'slide'
				});
			}
		}
	});
});

//取消保存用户
function cancelUpdateDev(){
	$("#saveOrUpdateDevForm")[0].reset();
	$("#SaveOrUpdateDevWin").window("close");
}

//数据表
function initTable(){
	$("#TableData").datagrid({
		url:'${ctx}/department/findAllBmPage.htm',
		idField:'glbm',
		fitColumns:true,
		border:false,
		striped:true,
		pagination: true,
		pageSize: 10,                //每页记录数      
       	pageList: [5, 10, 15, 20, 30, 50], //分页记录数数组 
       // queryParams:{
   	     //startTime:$("#startTime").combobox('getValue'),
   	    // endTime:$("#endTime").combobox('getValue')
      //  },  
		columns:[[
			{field:'',checkbox:true,align:'center',split:true},
			{field:'glbm',title:'部门代码',width:'100',align:'center',split:true},
		  	{field:'bmmc',title:'部门名称',width:'200',align:'center',split:true},
		  	{field:'bmqc',title:'部门全称',width:'200',align:'center',split:true},
		  	{field:'fzr',title:'负责人',width:'120',align:'center',split:true},
		  	{field:'lxr',title:'联系人',width:'120',align:'center',split:true},
		  	{field:'lxdh',title:'联系电话',width:'180',align:'center',split:true},
		  	{field:'czhm',title:'传真号码',width:'180',align:'center',split:true},
		  	{field:'lxdz',title:'联系地址',width:'220',align:'center',split:true},
			{field:'cz',title:'操作',width:'100',align:'center',split:true,formatter:function(value,row,index){
		  		return "<a class=\"chense\" href=\"javascript:UpdateBxgsInfo('"+row.glbm+"')\" >修改</a>&nbsp;&nbsp;&nbsp;<a class=\"chense\" href=\"javascript:deleteBxgs('"+row.glbm+"')\" >删除</a>";
		  	}}
		]]
	});
}




//根据界面中的样件，过滤查询用户列表
function queryDataGrid(){
	var ggSelect = $("#ggSelect").val() == "--部门代码或名称--" ? "":$("#ggSelect").val();
	$("#TableData").datagrid("load",{
		glbm:ggSelect,
		bmmc:ggSelect
	});
}

//删除用户信息
function deleteBxgs(ids){
		var r=confirm("确认要删除用户信息吗？删除后将不可恢复！");
		if(r){
			$.ajax({
				url:'${ctx}/department/delDepartment.htm',
				type:'POST',
				data:{
					ids:ids
				},
				success:function(data){
					if(data =="true"){
						queryDataGrid();
					}else{
						$.messager.show({
							title:'操作失败',
							msg:'操作失败，请联系管理人员',
							timeout:5000,
							showType:'slide'
						});
					}
				}
			});
		} 
}


//删除用户信息
function deleteBxgss(){
	var ids = $("#TableData").datagrid("getSelections");//getSelections
	var selectValues = ""; 
	for(var i=0;i<ids.length;i++){ 
		if(i==0){
			selectValues+=ids[i].glbm;
		}else{
			selectValues+=","+ids[i].glbm;
		} 
	}
	if(selectValues ==""){
		alert("请先选择要删除的记录！");
		return;
	}
	var r=confirm("确认要删除用户信息吗？删除后将不可恢复！");
	if(r){
		debugger;
		$.ajax({
			url:'${ctx}/department/delDepartment.htm',
			type:'POST',
			data:{
				ids:selectValues
			},
			success:function(data){
				if(data =="true"){
					queryDataGrid();
				}else{
					$.messager.show({
						title:'操作失败',
						msg:'操作失败，请联系管理人员',
						timeout:5000,
						showType:'slide'
					});
				}
			}
		});
	}	
}

//弹出用户对话框
function UpdateBxgsInfo(id){ 
	$('#saveOrUpdateDevForm').form('clear');//清空表单
	$("#saveLx").attr("value","xg");
	$("#glbm").attr("readonly","readonly");
	$("#glbm").css("color","#c8c8c8");
	$('#SaveOrUpdateDevWin').window('open');
	$.ajax({
		type:'POST',
		url:'${ctx}/department/findDepartmentByGlbm.htm',
		data:{glbm:id},
		dataType:'json',
		success:function(data, textsfzmhmus, jqXHR){
			$('#saveOrUpdateDevForm').form('load',data);
		}
	});
}




//弹出新增用户对话框
function AddWindow(){
	$('#saveOrUpdateDevForm').form('clear');
	$("#saveLx").attr("value","");
	$("#id").removeAttr("readonly");
	$('#SaveOrUpdateDevWin').window('open');
}

function updateDev(){
	debugger;
	var f=0;
	var a = new Array();
	a.push("glbm|部门代码");
	a.push("bmmc|部门名称");
	a.push("bmqc|部门全称");
	a.push("fzjg|发证机关");
	for(var i=0;i<a.length;i++){
		var id=a[i].split("|")[0];
		var name=a[i].split("|")[1];				
			if($("#"+id).val()==""){
				f=1;
				alert(name+"不能为空！");
				return;
			}
		}
	if($("#saveLx").val()==""){
		if(f==0){
			$.ajax({
				type:'POST',
				url:'${ctx}/department/findDepartmentByGlbm.htm',
				data:{glbm:$('#glbm').val()},
				dataType:'json',
				success:function(data,textStatus,jqXHR){
					if(!data==null){
						alert("部门信息已存在！！");
					}else{
						$("#saveOrUpdateDevForm").submit();
					}
				}
			});
		}
	}else{
		$("#saveOrUpdateDevForm").submit();
	}
	
}
	
	function ipIsValid(ip){
		var regex = new RegExp("\^((25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]\\d|\\d)\\.){3}(25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]\\d|\\d)\$");   
		return regex.test(ip);
	}
	function yhdhIsValid(yhdh){
		var regex=new RegExp("\^[_a-zA-Z0-9\u4e00-\u9fa5]{1,32}\$");
		return regex.test(yhdh);
	}
	function lengthIsValid(str){
		var strlength= str.replace(/[^x00-xff]/g,"01").length;
		return strlength<=32;
	}
	function sfzmhmIsValid(sfzmhm){ 
		var regex15=new RegExp("\^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}\$");
		var regex18=new RegExp("\^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X)\$");
		return regex15.test(sfzmhm)||regex18.test(sfzmhm);
	}
		
	</script>
	
</body>
</html>
